﻿using Alos.Common;
using Alos.Entity;
using Alos.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;

namespace Alos.LanClass.Api
{
    /// <summary>
    /// 备课信息获取
    /// </summary>
    public class LessionController : ApiController
    {
        IReLessionService ReLessionService;
        IReTeachRecordService ReTeachRecordService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_ReLessionService"></param>
        public LessionController(IReLessionService _ReLessionService,
                                 IReTeachRecordService _ReTeachRecordService)
        {
            ReLessionService = _ReLessionService;
            ReTeachRecordService = _ReTeachRecordService;
        }
        /// <summary>
        /// 根据备课编号获取备课步骤
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("api/lession/steps")]
        public async Task<JsonRtn<List<dynamic>>> steps(int id)
        {
            var jsRtn = new JsonRtn<List<dynamic>>();
            jsRtn.data = await ReLessionService.GetStepByLessionID((int)id);
            return jsRtn;
        }
        /// <summary>
        /// 根据章节编号加载课时
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("api/lession/period")]
        public async Task<JsonRtn<List<dynamic>>> period(int id)
        {
            var jsRtn = new JsonRtn<List<dynamic>>();
            jsRtn.data = await Task.Factory.StartNew(obj =>
            {
                var param = (dynamic)obj;
                return ReLessionService.GetReLessionClassPeriodByChapterID((int)param.lid, (int)param.uid).ToList();
            }, new { lid = id, uid = Common.Current.User.id });
            return jsRtn;
        }
        /// <summary>
        /// 学生登录后  等待老师准备上课
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("api/lession/inclass")]
        public async Task<JsonRtn<dynamic>> inClass(int cid)
        {
            var jsRtn = new JsonRtn<dynamic>();
            jsRtn.data = await Task.Factory.StartNew(obj =>
            {
                var param = (dynamic)obj;
                return ReTeachRecordService.isBeginTeach((int)param.cid);
            }, new { cid = cid });
            return jsRtn;
        }
    }
}